

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class mapa
 */
@WebServlet("/mapa")
public class mapa extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public mapa() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=ISO-8859-2");
		PrintWriter out = response.getWriter();
		String odp="";
			String adres = new String(request.getParameter("adres").getBytes("ISO8859_1"), "UTF8");
			try {
				Connection con =mb.commons.DbConnection.getConnection 
						  ();

			  Statement stmt = con.createStatement();
			  ResultSet rs = stmt.executeQuery("SELECT * FROM oddzialy WHERE adres LIKE '%"+adres+"%'");
			  
			  while(rs.next()){
				 odp+=rs.getString("adres")+"|"+rs.getString("telefon")+"|"+rs.getString("nazwa")+"|"+rs.getString("long")+"|"+rs.getString("lat")+";";	  
			  }	  
			  out.println(odp);
			  
			} catch (Exception e) {
				out.println("sebastian");
			}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
		
	}

}
